/*
 * song.c
 *
 *  Created on: Mar 1, 2013
 *      Author: George
 */
#include "common.h"
static int toggle_md = 0;
static int current_note = 0;
static int tempo = 0;
static int dur = 3;
static int tempo_flag = 1;
typedef enum {
	B3 	=0,
	C4 	=1,
	Cs4 =2,
	D4 	=3,
	Ds4	=4,
	E4	=5,
	F4	=6,
	Fs4	=7,
	G4	=8,
	Gs4	=9,
	A4	=10,
	As4	=11,
	B4	=12,
	C5	=13,
	Cs5	=14,
	D5	=15,
	Ds5	=16,
	E5	=17,
	F5	=18,
	Fs5	=19,
	G5	=20,
	Gs5 =21,
	A5  =22,
	As5 =23,
	p   =-1
}Pitch;
void play_next()
{
	
	/*Never Gonna Give You Up*/
	/*
	int pitch_sequence[] = 	{	9, 11, 13, 11, 18, -1, 18, -1, 16, -1, -1, -1,
								9, 11, 13, 11, 16, -1, 16, -1, 14, -1, -1, -1,
								9, 11, 14, 11, 14, -1, 16, -1, 13, -1, -1, -1,
								11,11,  9,  9, 16, -1, 14, 14
									};
	int dur_sequence[] 	 =	{	0										
												};
	*/
	
	/* Call me maybe */
	/*
	int pitch_sequence[] = 	{	8, -1, -1 , 0, -1, 3,-1,  8,-1,  3, -1, -1,
							0, -1, 0, -1, 3, -1, 12, 12, 8, -1, -1,
							8, -1, 12, -1, 10, -1, 10, -1, 8, -1, -1,
							8, -1, 13, -1, 10, -1, 10, -1, 8, -1, -1
										};
	int dur_sequence[] 	 =	{	0										
												};
	*/
	
	/*Star Wars*/
	
	int pitch_sequence[] = 	{	8, 8, -1, 8, 8, -1, 8, 8,  -1, 4,  4,  11, 8, 8,-1, 4, 4,  11,  8, 8,-1, -1, -1, 
								15, 15, -1, 15, 15, -1, 15, 15, -1, 16,  16,  11, 7, 7, -1, 3, 3, 11,  8, 8, -1, -1, -1,
								8, 8, -1, 8, 8, -1, 8, 8,  -1, 4,  4,  11, 8, 8,-1, 4, 4,  11,  8, 8,-1, -1, -1, 
								15, 15, -1, 15, 15, -1, 15, 15, -1, 16,  16,  11, 7, 7, -1, 3, 3, 11,  8, 8, -1, -1, -1,
								8, 8, -1, 8, 8, -1, 8, 8,  -1, 4,  4,  11, 8, 8,-1, 4, 4,  11,  8, 8,-1, -1, -1, 
								15, 15, -1, 15, 15, -1, 15, 15, -1, 16,  16,  11, 7, 7, -1, 3, 3, 11,  8, 8, -1, -1, -1,
								8, 8, -1, 8, 8, -1, 8, 8,  -1, 4,  4,  11, 8, 8,-1, 4, 4,  11,  8, 8,-1, -1, -1, 
								15, 15, -1, 15, 15, -1, 15, 15, -1, 16,  16,  11, 7, 7, -1, 3, 3, 11,  8, 8, -1};
	//int dur_sequence[] 	 =	{0};										
	
	/*Mario Bros*/
	/*
	int pitch_sequence[] = 	{	
												};
	int dur_sequence[] 	 =	{											
												};			
	 */
	/*
	int pitch_sequence[] = {	A4, C5, D5, -1, D5, -1, D5, 
								E5, F5, -1, F5, -1, F5,  G5, E5, -1, E5, -1,
								D5, C5, C5, D5, -1, -1, 
								A4, C5, D5, -1, D5, -1, D5, 
								E5, F5, -1, F5, -1, F5,  G5, E5, -1, E5, -1,
								D5, C5, D5, -1, -1,
								A4, C5, D5, -1, D5, -1, D5, F5, G5, -1, G5, -1,
								G5, A5, As5, p, As5, p, A5, G5, A5, D5, p, p,
								D5, E5, F5, F5, G5, p, A5, D5, p,
								D5, F5, E5, p, E5, p, E5, p,
								
								A4, C5, D5, -1, D5, -1, D5, 
								E5, F5, -1, F5, -1, F5,  G5, E5, -1, E5, -1,
								D5, C5, C5, D5, -1, -1, 
								A4, C5, D5, -1, D5, -1, D5, 
								E5, F5, -1, F5, -1, F5,  G5, E5, -1, E5, -1,
								D5, C5, D5, -1, -1,
								A4, C5, D5, -1, D5, -1, D5, F5, G5, -1, G5, -1,
								G5, A5, As5, p, As5, p, A5, G5, A5, D5, p, p,
								D5, E5, F5, F5, G5, p, A5, D5, p,
								D5, F5, E5, p, E5, p, D5, Cs5, p, D5,
								
								D5, D5, E5, F5, p, F5, p, F5,G5, A5
								};
	*/
	
	play_note(pitch_sequence[current_note], dur, tempo);
	//play_note(sequence[current_note]);
	current_note++;
}
void mod_tempo()
{
	if(toggle_md == 0) { toggle_md = 1; return; }
	toggle_md = 0;
	
	if(tempo_flag) tempo++;
	else tempo--;
	
	if(tempo > 6)
	{
		tempo_flag = 0;
		tempo -= 2;
	}
	else if(tempo < 0)
	{
		tempo_flag = 1;
		tempo += 2;
	}
	
	//current_note = 0;
}
